/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import domain.Consumption;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

/**
 *
 * @author Alberto
 */
public class ConsumptionDao {

    EntityManager em;
    EntityTransaction tx;

    public ConsumptionDao() {
        em = SingletonDao.getInstance().getEntityManager();
        tx = SingletonDao.getTx();
    }

    public Consumption getConsumption(Integer idC){
        Consumption b = (Consumption) em.createNativeQuery("select * from consumption as c where c.idCons='"+idC+"'", Consumption.class).getSingleResult();
        return b;
    }

    public void saveConsumption(Consumption c){
        tx.begin();
        em.persist(c);
        tx.commit();
    }

    public void removeConsumption (Consumption c){
        tx.begin();
        em.remove(c);
        tx.commit();
    }

}
